package cc.lj.internal.api.coupons.api.ticket.fallbackfactory;

import cc.lj.internal.api.coupons.api.ticket.CouponsSettlementFeignService;
import cc.lj.internal.api.coupons.dto.CouponsSettlementApiDTO;
import cc.lj.internal.api.coupons.dto.command.CouponsSettlementApiCommand;
import cc.lj.internal.core.http.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 电子券分摊结算数据查询fegin回退处理，可以打印出具体回退原因
 * 注意：只有配置文件中开启hystrix (feign.hystrix.enabled=true),该配置才会起作用
 * @author liangxifeng
 * @date 2022-01-12
 */
@Slf4j
@Component
public class CouponsSettlementFeignServiceFallbackFactory implements FallbackFactory<CouponsSettlementFeignService> {
    @Override
    public CouponsSettlementFeignService create(Throwable cause) {
        return new CouponsSettlementFeignService() {
            @Override
            public HttpResult<CouponsSettlementApiDTO> getSettlementData(CouponsSettlementApiCommand couponsSettlementApiCommand) {
                log.error("feign--请求电子券模块:通过展位号和券批次主键查询分摊结算数据出现异常,原因:" + cause.getMessage());
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage());
            }
        };
    }
}
